package com.notes.romania.arrayadapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.notes.romania.R;

public class FileArrayAdapter extends ArrayAdapter<String> {
	private final Activity context;
	private final ArrayList<String> names;

	static class ViewHolder {
		public TextView text;
		public ImageView image;
	}

	public FileArrayAdapter(Activity context, ArrayList<String> values) {
		super(context, R.layout.fileitem, values);
		this.context = context;
		this.names = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.fileitem, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.text = (TextView) rowView.findViewById(R.id.textView1);
			viewHolder.image = (ImageView) rowView.findViewById(R.id.imageView1);
			rowView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) rowView.getTag();
		String s = names.get(position);
		holder.text.setText(s);
	
		if(position == 0)
			holder.image.setImageResource(R.drawable.back_icon);
		else	
			if (s.endsWith(".mp3"))
				holder.image.setImageResource(R.drawable.mp3_icon);
			else 
				holder.image.setImageResource(R.drawable.folder_icon);
				
		return rowView;
	}
} 